﻿<!DOCTYPE html>
<head>
    <title>合成测试示例</title>
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

</head>

<body>
	<h2>合成测试示例</h2>
	<input type="button" value="TEST" onclick="play('今天天气不错，挺风和日丽的')" />
	<script src="js/md5.js"></script>	
	<script src="js/socket.io.js"></script>
	<script src='js/fingerprint.js'></script>
	<script src="js/tts.min.js"></script>
	<script type="text/javascript">
	    /**
		  * 初始化Session对象
		  */
	    var session = new IFlyTtsSession({
                                    'url' : 'http://webapi.openspeech.cn/',							
                                    'interval' : '30000', 
		      	'disconnect_hint' : 'disconnect',
		      	'sub' : 'tts'
			});

		var audio = null;
		
		/**
		  * 输入文本，输出语音播放链接 
		  * @content 待合成文本(不超过4096字节)
		  */
		function play(content) {
		    /***********************************************************以下签名过程需根据实际应用信息填入***************************************************/
		 
		    var appid = "55e39e60";  //应用APPID，在open.voicecloud.cn上申请即可获得
		    var SecretKey = "08a603918c0b5388";
		    var vcn = "xixy";
		    var timestamp = new Date().toLocaleTimeString();                      //当前时间戳，例new Date().toLocaleTimeString()
            	    var expires = 60000;                          //签名失效时间，单位:ms，例60000		
		    //!!!为避免secretkey泄露，签名函数调用代码建议在服务器上完成
		    var signature = faultylabs.MD5(appid + '&' + timestamp + '&' + expires + '&' + SecretKey);		
		   /************************************************************以上签名过程需根据实际应用信息填入**************************************************/
		   
		   var params = { 
			"params" : "aue = speex-wb;7, ent = intp65, spd = 50, vol = 50,tte = utf8, caller.appid=" + appid + ",timestamp=" + timestamp + ",expires=" + expires+",vcn ＝"+vcn, 
			"signature" : signature, 
			"gat" : "mp3"
			};

		session.start(params, content, function (err, obj){
		    if(err) {
			    alert("语音合成发生错误，错误代码 ：" + err);
		    } else {
		        if(audio != null)
			{
			    audio.pause();
			}
			audio = new Audio();
			audio.src = '';
            			audio.play();
			audio.src = "http://webapi.openspeech.cn/" + obj.audio_url;
			audio.play();
		    }
		    });
		};
		
	</script>
</body>
</html>
